<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@include file="/include/common/formbackhead.jsp"%>
<%!
private class PageAction extends BaseAction{
	ResultSet rs = null;
	
	//准备action的环境变量 每次请次都会执行此方法 可在此方法中初如化一些变量
	protected void prepareActionEnv() throws Exception{
		
	}
	
	//加載頁面默認數據
	protected boolean onLoadDefault() throws Exception{
		if(!form.isNullOrEmpty("pan001sn")){
			rs = utils.executeQuery("fs1","select * from pan..pan001 where sn = '"+form.gpsv("pan001sn")+"'");
			if(rs.next()){
				form.FromResultSet(rs, false);
				if("0".equalsIgnoreCase(form.gpsv("enab"))){
					ret.setWarningInfo("此單已取消!");
					page.getToolbar().disableAllButtonExcept("newnext");
				}
			}else{
				ret.setWarningInfo("此單已刪除,如需要請重新新增!");
				page.getToolbar().disableAllButtonExcept("newnext");
			}
		}
		return true ;
	}
	
	//处理储存驗證
	protected void onSaveValidate() throws Exception{
		
	}
	
	//執行儲存
	protected void doSave() throws Exception{
		//1.儲存
		CrudDataEntity crud = form.getCrudDataEntity("fs1","pan..pan001","sn");
		crud.spsv("sn", form.gpsv("pan001sn"));
		crud.setSpportSimple(true);
		crud.spsv("userid", form.gpsv("userid"));
		crud.spsv("pwd", form.gpsv("pwd"));
		crud.spsv("chname", form.gpsv("chname"));
		crud.spsv("sex", form.gpsv("sex"));
		crud.spsv("email", form.gpsv("email"));
		crud.spsv("uitype", form.gpsv("uitype"));
		crud.spsv("enab", form.gpsv("enab"));
		if(crud.isInsert()){
			crud.setGetLastKey(true);
			crud.appendCols("prgName,crtDay,crtName,crtIp,updDay,updName,updIp");
		}else{
			crud.appendCols("prgName,updDay,updName,updIp");
		}
		crud.save();
		
		ret.setOkInfo("儲存成功!");
		
		
        utils.getSession().setAttribute("chname", crud.gpsv("chname"));
        utils.getSession().setAttribute("email", crud.gpsv("email"));
        utils.getSession().setAttribute("uitype", crud.gpsv("uitype"));
                
		if(form.isNullOrEmpty("pan001sn")){
			form.spsv("pan001sn", crud.gpsv("sn"));
		}
	}
	


//刪除驗證
	protected void onDeleteValidate() throws Exception{
		if(form.isNullOrEmpty("pan001sn")){
			ret.setErrorInfo("沒有主鍵值,不能取消!");
		}
	}
	
	//執行刪除
	protected void doDelete() throws Exception{
		CrudDataEntity crud = form.getCrudDataEntity("fs1","pan..pan001","sn");
		crud.spsv("sn", form.gpsv("pan001sn"));
		crud.delete();
		form.Reset();
		page.getToolbar().disableAllButtonExcept("newnext");
		ret.setOkInfo("刪除成功!");
	}
}
%>
<%@include file="/include/common/formbackend.jsp"%>
